﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yule8xCommon.Applib;
using Yule8xCommon.Typelib;
using Yule8xWechat.Applib;

namespace Yule8xWechat.Test
{
    public partial class PayTransfer : System.Web.UI.Page
    {
        protected string product_name, signstr, out_trade_no;
        protected decimal order_amount;
        protected void Page_Load(object sender, EventArgs e)
        {
            // 微信公众号第三方支付中转页面
            string query = RequestUtil.GetString("query");
            string sign = RequestUtil.GetString("sign");
            out_trade_no = RequestUtil.GetString("tradeno");
            if (query.Length < 1 || sign.Length < 1)
            {
                RedirectUtil.RedirectTimer(false, "参数错误", new string[] { "提交的参数不完整!" });
            }
            string signtemp = MD5Util.GetShortMD5(AppInfo.EncryptKey + query);
            if (signtemp != sign)
            {
                RedirectUtil.RedirectTimer(false, "签名不正确", new string[] { "数据签名错误!" });
            }
            BuyDiamondAttachData queryData;
            try
            {
                queryData = JSON.parse<BuyDiamondAttachData>(query);
                if (null == queryData)
                {
                    RedirectUtil.RedirectTimer(false, "请求参数格式有误!", new string[] { "请求参数格式有误!" });
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            product_name = string.Format("购买{0}颗钻石", queryData.num);
            order_amount = queryData.amo;
            bool onecentpay = RuntimeDataUtil.CheckOnecentPay(queryData.uid); // 一分钱支付
            if (onecentpay)
            {
                order_amount = 0.01m;
            }
            if (onecentpay)
            {
                LogUtil.Instance.WriteError(string.Format("[购买钻石] user_id={0}, number={1}, amount={2} 使用OCP支付模式", queryData.uid, queryData.num, order_amount), null);
            }
            signstr = MD5Util.GetShortMD5(string.Format("{0}amount={1}", AppInfo.EncryptKey, order_amount));
        }
    }
}